package cn.bitkit.mybatis.builder;

import java.util.Map;
import java.util.StringJoiner;

import cn.bitkit.mybatis.base.BaseSqlBuilder;
import cn.bitkit.mybatis.CriteriaHandler;
import cn.bitkit.mybatis.entity.EntityClass;

/**
 * @author changbo
 */
public class SelectBuilder implements BaseSqlBuilder {

	@Override
	public boolean supportLinkTable() {
		return true;
	}

	@Override
	public String build(EntityClass entityClass, Map<String, Object> paramMap) {
		StringJoiner sql = new StringJoiner(" \n");
		sql.add("SELECT " + CriteriaHandler.getSelect(entityClass, paramMap));
		sql.add("FROM " + CriteriaHandler.getFrom(entityClass, paramMap));
		sql.add("<where>");
		sql.add(CriteriaHandler.getWhereSql(paramMap));
		sql.add("</where>");
		sql.add("LIMIT 1");
        return sql.toString();
	}

}
